<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-04 16:53:56
 * @LastEditTime: 2023-10-18 13:43:40
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Http\Services\Comprehensive;


use App\Http\Services\Service;
use App\Repositories\ComprehensiveCarDetailsRepository;
use App\Repositories\ComprehensiveCarRepository;
use App\Repositories\ComprehensiveCarryCarDetailRepository;


class CarCarryDetailService extends Service
    {
    public $details;
    public function __construct(ComprehensiveCarryCarDetailRepository $repository)
        {
        $this->repository = $repository;
        }

    public function list()
        {
        $data = $this->repository->condition(request())->getGrid();
        return $data;
        }
    protected function saveCarryItems()
        {
        $request  = request();
        $carry_id = $request->id;
        $row_ids  = $request->row_ids;
        $details  = $this->repository->whereIn("id", $row_ids)->get();
        return $details->filter(function ($detail) use ($carry_id)
            {
            return $detail->source->addCarryItem($carry_id, $detail->code);
            });
        }
    protected function saveCarItems()
        {
        $request = request();
        $car_id  = $request->id;
        $row_ids = $request->row_ids;
        $details = $this->repository->whereIn("id", $row_ids)->get();
        return $details->filter(function ($detail) use ($car_id)
            {
            $source = $detail->source;
            return $source->addCarItem($source->getSourceAddr(), $source->getTargetAddr(), $car_id, $detail->code);
            });
        }
    }